//有一次抽奖机会
var awardTime = true;
var exist = true;
var oLogin_hint = new ele('login_hint');
var oBox_change = new ele('box_change');
var sMobile = null;
var arr = ['_1yuan', '_10jifen', '_thankyou', '_10yuan', '_50jife'];
var prize = ['1元现金红包','10积分','感谢参与','10元现金红包','50积分']
var num;
var oBox_turn = new ele('box_turn');
var oBox_pointer = new ele('box_pointer');
var oBox_record_prize = new ele('box_record_prize');
var oBox_dial = new ele('box_dial');

//验证登陆
function checkMobile() {
	localStorage.setItem('1', 'true');
	sMobile = document.mobileform.email.value
	console.log(sMobile);
	if(!(/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(sMobile))) {
		oLogin_hint.classList.remove('hide');
		document.mobileform.email.focus();
		return false;
	} else {
		for(var i = 0; i < localStorage.length; i++) {
			var key = localStorage.key(i);
			var value = localStorage.getItem(key);
			if(sMobile == key) {
				exist = true;
				break;
			} else {
				exist = false;
			}
		}
		
		//已经注册过用户名了
		if(exist) { 
			awardTime = !value ? 1 : 0;
			oBox_change.innerText =+ awardTime;
			if(awardTime) {
				oBox_pointer.onclick = turn;
			} else {
				oBox_change.innerText = +awardTime;
				oBox_pointer.classList.add('blackPointer');
				oBox_pointer.onclick = null;
			}
		} else {
			oBox_pointer.onclick = turn;
			localStorage.setItem(sMobile, awardTime);
		}
		oLogin_hint.classList.add('hide')
		hideShow('login');
		hideShow('box');
	}
	return false;
}

//抽奖
function turn() {
	oBox_dial.classList.add('glint');
	oBox_turn.className = 'box_turn';
	num = Math.floor(Math.random() * 5);
	oBox_turn.classList.add(arr[num]);
	awardTime = false;
	localStorage.setItem(sMobile, awardTime);
	oBox_change.innerText = +awardTime;
	setTimeout(function() {
		oBox_record_prize.innerText = prize[num];
		oBox_pointer.classList.add('blackPointer');
		oBox_pointer.onclick = null;
	}, 2000)
}

//显示隐藏
function hideShow(id) {
	document.getElementById(id).classList.toggle('hide');
}

//创建元素
function ele(id) {
	return document.getElementById(id);
}

//清除缓存
function clearStorage() {
	localStorage.clear();
}